<template>
	<view class="wp">
		<!-- <view class="nav_blcok"></view> -->
		<!-- 直播小弹框安卓端 -->
		<!-- #ifndef H5-->
		<jcvideo-msg class="h1_jcvideo_msg" :style="{top: JMsgTop+'px'}" :JMsgTop.sync="JMsgTop" v-if="jcvideoMsgSHAn"
			style="position: absolute;z-index: 501;" :visible.sync="jcvideoMsgSH" :jcvideoMsgInfo="jcvideoMsgInfo">
		</jcvideo-msg>
		<!-- #endif -->
		<view class="Gradient">
			<tab-search></tab-search>
			<view class="body">
			</view>
		</view>
		<!-- 页面显示 -->
		<home id="home" ref="home"></home>
		<!-- 活动弹层 -->
		<jwarn-msg :JsrcLink="activitycont" :JmsgShow.sync="jwarnMsgSH"></jwarn-msg>
		<!-- 弹出条 -->
		<!-- <pengpai-dom style="position: relative;z-index: 900;" ref="pengpai" :list="pengpaiList" @changload="changload($event)"></pengpai-dom> -->

		<!-- 直播小弹框IOS端 -->
		<!-- #ifndef H5-->
		<jcvideo-msg class="h1_jcvideo_msg" :style="{top: JMsgTop+'px'}" :JMsgTop.sync="JMsgTop" v-if="!jcvideoMsgSHAn"
			style="position: fixed;z-index: 501;" :visible.sync="jcvideoMsgSH"
			:jcvideoMsgInfo="jcvideoMsgInfo"></jcvideo-msg>
		<!-- #endif -->
		<!-- 直播小弹框H5 -->
		<!-- #ifdef H5 -->
		<jcvideo-msg class="h1_jcvideo_msg" :style="{top: JMsgTop+'px'}" :JMsgTop.sync="JMsgTop"
			style="position: fixed;z-index: 501;" :visible.sync="jcvideoMsgSH"
			:jcvideoMsgInfo="jcvideoMsgInfo"></jcvideo-msg>
		<!-- #endif -->
	</view>
</template>

<script>
	import JwarnMsg from '@/components-home/pages/JwarnMsg.vue'
	import JcvideoMsg from '../../components-home/components/JCvideoMsg.vue'
	import home from '@/pages/home_v1.vue'
	import Jswiper from '@/components-home/pages/Jswiper.vue'
	import tabSearch from "@/home_page/components/tab_search.vue"
	export default {
		components: {
			JwarnMsg,
			JcvideoMsg,
			home,
			Jswiper,
			tabSearch,
		},
		data() {
			return {
				// 直播小弹框相关
				JMsgTop: 290, //距离顶部位置
				jcvideoMsgSH: false, //直播小弹框是否显示
				jcvideoMsgSHAn: false, //是否是安卓端判断
				jcvideoMsgInfo: {}, //播放数数据

				// 弹出条相关
				pengpaiList: [], //弹出条数据

				// 活动弹窗相关
				jwarnMsgSH: false, //活动是否显示
				activitycont: {}, //活动弹层数据
				info: {
					banner: [],
				},
				bg: '#8405dc',
				danmuList:[],
				current: 0,
				meunList: [],
				mid: 0,
				code: ''
			}
		},
		async onLoad(options) {
			let mid = '';
			if (options.mid) {
				mid = options.mid;
				this.mid = options.mid;
			}
			if (options.scene) {
				mid = options.scene;
			}
			uni.setStorageSync('mid', mid);
			if(options.code) this.code = options.code;
			// await this.$onLaunched;
			if(!uni.getStorageSync('token')){
				this.getToken();
			}
		},
		onShow() {
			// 获取活动弹窗
			this.getActivePage();

			//初始化首页
			this.$nextTick(() => {
				this.$refs.home.init();
			})

			//获取直播小框数据
			this.zhiboInfo();
			this.getMenu();

			// 分享
			//this.$share();
             
			// 升级
			// #ifdef APP-PLUS
			this.$upgrade();
			// #endif
		},
		onHide() {
			this.jcvideoMsgSH = false;
		},
		onPageScroll(e) {
			const windowHeight = uni.getSystemInfoSync().windowHeight;
			let query = uni.createSelectorQuery().in(this);
			query.select('#home').boundingClientRect(data => {
				if (data.height + data.top < windowHeight * 2) {
					// this.$refs.home.getBrand();
				}
			}).exec();
			uni.$emit('onPageScroll', e.scrollTop);//传递参数
		},
		methods: {
			getToken(){
				/*#ifdef H5*/
				this.$axios('login/autoGzlogin','POST','member',{
					mid: this.mid,
					code: this.code,
				}).then(res=>{
					if(res.data.code == 300001){
						this.$navTo(res.data.data);
					}else if(res.data.code == 200){
						uni.setStorageSync('token', res.data.data);
						uni.setStorageSync('Jh_recotabshops', 1);
						this.getSharePath();
					}
				})
				/*#endif*/
				/*#ifndef H5*/
				uni.login({
					provider: 'weixin',
					success:res=> {
						this.$axios('login/autologin','POST','member',{
							mid: this.mid,
							code: res.code
						}).then(res=>{
							if(res.data.code == 200){
								uni.setStorageSync('token', res.data.data);
								uni.setStorageSync('Jh_recotabshops', 1);
								this.getSharePath();
							}
						})
					}
				})
				/*#endif*/
			},
			getMenu() {
				this.$axios('home/shopcalss', 'POST', 'shop').then((res => {
					if (res.data.code == 200) {
						this.meunList = res.data.data;
					}
				}))
			},
			getActivePage() {
				let date = uni.getStorageSync('pageDate'),
					newDate = new Date() - 0;
				if (date && newDate - date < 7200000) {
					return false;
				}
				this.$axios('home/activepage', 'POST', 'shop').then(res => {
					if (res.data.code == 200) {
						this.activitycont = res.data.data;
						if (res.data.data != '') {
							this.jwarnMsgSH = true;
							uni.setStorageSync('pageDate', newDate);
						} else {
							this.jwarnMsgSH = false;
						}
					} else {
						this.$api.msg(res.data.data);
					}
				});
			},
			// 直播小窗口是否显示
			zhiboInfo() {
				switch (uni.getSystemInfoSync().platform) {
					case 'android':
						this.jcvideoMsgSHAn = true
						break;
					case 'ios':
						this.jcvideoMsgSHAn = false
						break;
				}
				this.$axios('home/zhibo', 'POST', 'shop').then(res => {
					if (res.data.code == 200 && res.data.data.isshow > 0) {
						this.jcvideoMsgSH = true;
						this.jcvideoMsgInfo = res.data.data;
					} else {
						this.jcvideoMsgSH = false;
					}
				})
			}
		},
	}
</script>

<style lang="scss">
	page {
		background: #f8f8f8;
	}
	.wp /deep/ .Jc_swiper_wp{
		background: none;
		padding: 0;
	}
	.wp {
		position: relative;
		overflow: hidden;
	}
	.Gradient{
		// background: linear-gradient($bg-color, #0e0217);
		background: linear-gradient($bg-color, #2C0087);
	}
	.nav_blcok {
		height: var(--status-bar-height);
	}

	.h1_jcvideo_msg {
		right: 0;
	}
	.body {
		position: relative;
		padding-top: calc(var(--status-bar-height) + 126rpx);
		z-index: 100;
	}
</style>